package com.itheima.reggie.controller;

import com.itheima.reggie.common.ResultInfo;
import com.itheima.reggie.domain.Cart;
import com.itheima.reggie.service.CartService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

@RestController
public class CartController {
    @Autowired
    private CartService cartService;
    //添加购物车
    @PostMapping("/cart/add")
    public ResultInfo add(@RequestBody Cart cartParam){
        //接收添加的参数并返回
      Cart cart =  cartService.add(cartParam);
      return ResultInfo.success(cart);
    }
    //显示购物车
    @GetMapping("/cart/list")
    public ResultInfo findALL(){
       List<Cart> cartList= cartService.findAll();
       return ResultInfo.success(cartList);
    }
    //清空购物车
    @DeleteMapping("/cart/clean")
    public ResultInfo delete(){
        cartService.delete();
        return ResultInfo.success(null);
    }
    //修改购物车
    @PostMapping("/cart/sub")
    public ResultInfo update(@RequestBody Cart cartPram) {
        Cart cart = cartService.update(cartPram);
        return ResultInfo.success(cart);
    }
}
